import SuperScrollView from "../../Script/components/SimpleScrollView";
import SimpleScrollViewPlus from "../../Script/components/SimpleScrollViewPlus";


const { ccclass, property } = cc._decorator;

@ccclass
export default class FrameLoading extends cc.Component {

    @property(SimpleScrollViewPlus)
    ndSv: SimpleScrollViewPlus = null;

    @property(cc.EditBox)
    numEdit: cc.EditBox = null;

    @property(cc.Prefab)
    pfItemPrefab: cc.Prefab = null;

    @property(cc.Prefab)
    pfItemPrefab2: cc.Prefab = null;

    dataList: any[] = [];

    dataList2: any[] = [];

    start() {
        for (let i = 1; i <= 200; i++) {
            this.dataList.push(i);
        }

        for (let i = 1; i <= 100; i++) {
            this.dataList2.push(i);
        }
    }


    commonLoadingItems() {

        this.frameLoadingItems();
    }

    frameLoadingItems() {
        let cb = () => {
            this.ndSv.scrollToIndex(300);
        }

        for (let i = 0; i < this.dataList.length; i++) {
            let node = cc.instantiate(this.pfItemPrefab);
            this.ndSv.add(node, this.dataList[i], 'Item');
        }

        for (let i = 0; i < this.dataList2.length; i++) {
            let node = cc.instantiate(this.pfItemPrefab2);
            this.ndSv.add(node, this.dataList2[i], 'Item');
        }

        this.ndSv.create();
    }

    deleteAllItems() {
        this.ndSv.deleteAll();
    }

    deleteSingle() {
        let numStr = this.numEdit.string;

        let index = Number(numStr);

        this.ndSv.deleteItem(index);
    }

    updateSingle() {
        let numStr = this.numEdit.string;

        let index = Number(numStr);

        this.ndSv.updateItem(index, 999, "Item");
    }
}
